package com.edu.marker.activities;

import java.util.ArrayList;

import com.edu.marker.R;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class TipsExamAdapter extends BaseAdapter{
	private ArrayList<String> list = new ArrayList<String>();
	public LayoutInflater myLayoutInflater = null;
	public Handler myHandler;
	
	public TipsExamAdapter(Context myContext,ArrayList<String> mylist,Handler handler){
		this.list = mylist;
		this.myHandler = handler;
		myLayoutInflater = (LayoutInflater)myContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	
	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if(convertView==null){
			convertView = myLayoutInflater.inflate(R.layout.tips_exam_listitem, null);
			holder = new ViewHolder();
//			holder.item_image = (ImageView)convertView.findViewById(R.id.index_installedapp_icon);
			holder.item_text = (TextView)convertView.findViewById(R.id.tips_exam_item_name);
			
			convertView.setTag(holder);
		}
		else{
			holder = (ViewHolder)convertView.getTag();
		}
		if(list.size()>0){
			final String name = list.get(position);
//			holder.item_image.setImageDrawable(app.getApp_icon());
			holder.item_text.setText(name);
		
		convertView.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v) {
				Message msg = myHandler.obtainMessage(2,position);
				myHandler.sendMessage(msg);
			}
		});
		}
		
		return convertView;
	}
	
	class ViewHolder{
		ImageView item_image;
		TextView item_text;
	}

}
